using System;
using System.Security.Cryptography.X509Certificates;

namespace NHConfiguration
{
    public static class CertificateHelper
    {
        public static X509Certificate2 LoadFromFile(string file)
        {
            if (file != null)
                file = file.Trim();

            if (string.IsNullOrEmpty(file))
                return null;

            var parts = file.Split('|');
            if (parts.Length > 2)
                throw new ArgumentException("Certificate file name format not valid, but be in the format 'file|password'");

            var fullPath = PathHelper.LocateServerPath(parts[0].Trim());

            var password = string.Empty;
            if (parts.Length == 2)
                password = parts[1];

            return new X509Certificate2(fullPath, password);
        }
    }
}